package cn.yuanqiao.web.controller.archive.liyong;

import cn.yuanqiao.archive.liyong.domain.YqMyCollect;
import cn.yuanqiao.archive.liyong.service.IYqMyCollectService;
import cn.yuanqiao.common.web.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.web.page.TableDataInfo;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 我的收藏夹
 *
 * @ProjectName: JZSDAS
 * @Package: cn.yuanqiao.archive.liyong.controller
 * @ClassName: YqMyCollectController
 * @Author: lenovo
 * @Description: hbWang
 * @Date: 2023/8/9 15:30
 * @Version: 1.0
 */
@RestController
@RequestMapping("/archive/my/collect")
public class YqMyCollectController extends BaseController {
    @Autowired
    private IYqMyCollectService yqMyCollectService;

    /**
     * 查询我的收藏夹列表
     */
    //@PreAuthorize("@ss.hasPermi('archive:COLLECT:list')")
    @Log(title = "我的收藏夹", businessType = BusinessType.SELECT)
    @PreAuthorize("@ss.hasPermi('archive:myCollect:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody YqMyCollect yqMyCollect) {
        startPage();
        List<YqMyCollect> list = yqMyCollectService.selectYqMyCollectList(yqMyCollect);
        return getDataTable(list);
    }

    /**
     * 获取我的收藏夹详细信息
     */
    //  @PreAuthorize("@ss.hasPermi('archive:COLLECT:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(yqMyCollectService.selectYqMyCollectByDaId(id));
    }

    /**
     * 新增我的收藏夹
     */
    @PreAuthorize("@ss.hasPermi('archive:myCollect:add')")
    @Log(title = "我的收藏夹", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YqMyCollect yqMyCollect) {
        return toAjax(yqMyCollectService.insertYqMyCollect(yqMyCollect));
    }

    /**
     * 修改我的收藏夹
     */
    //  @PreAuthorize("@ss.hasPermi('archive:COLLECT:edit')")
    @Log(title = "我的收藏夹", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YqMyCollect yqMyCollect) {
        return toAjax(yqMyCollectService.updateYqMyCollect(yqMyCollect));
    }

    /**
     * 删除我的收藏夹
     */
    @PreAuthorize("@ss.hasPermi('archive:myCollect:remove')")
    @Log(title = "我的收藏夹", businessType = BusinessType.DELETE)
    @DeleteMapping("/{daIds}")
    public AjaxResult remove(@PathVariable String[] daIds) {
        return toAjax(yqMyCollectService.deleteYqMyCollectByDaIds(daIds));
    }

    /**
     * 判断收藏权限
     */
    @PostMapping("/queryAuthority")
    public AjaxResult queryAuthority() {
        return success(yqMyCollectService.queryAuthority());
    }
}
